//
//  QJMineOrderFooterThree.m
//  QuanJieShopProject
//
//  Created by 刘中义 on 2018/3/2.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJMineOrderFooterThree.h"
#import "YFLogisticsViewController.h"
@implementation QJMineOrderFooterThree
-(void)awakeFromNib{
    
    [super awakeFromNib];
    // 取消订单
    self.wuliuBtn.layer.borderWidth = 1;
    self.wuliuBtn.layer.borderColor = YFColor_Red.CGColor;
    [self.wuliuBtn setTitleColor:YFColor_Red forState:UIControlStateNormal];
    
    // 删除订单
    self.querenBtn.layer.borderWidth = 1;
    self.querenBtn.layer.borderColor = YFColor_Red.CGColor;
    [self.querenBtn setTitleColor:YFColor_Red forState:UIControlStateNormal];
   
}

- (IBAction)wuliuAction:(UIButton *)button {
    
   
    YFLogisticsViewController *vc = [[YFLogisticsViewController alloc]init];
    vc.orderID = _model.order_id;
    UIViewController *VC = [self currentViewController];
    [VC.navigationController pushViewController:vc animated:YES];
    
}

- (IBAction)querenAction:(UIButton *)sender {
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
    [dict setObject:_model.order_id forKey:@"order_id"];
    
    [WWNetRequest fetchConfirmOrderWithParameters:dict success:^(id response) {
        
        [MBPHUD showAlertWithTitle:@"操作成功"];
        
    } failure:^(NSDictionary *error) {
        
    }];
    
}


- (void)footerUpdateModel:(MineOrderModel *)model{
    if (model) {
        _model = model;
        NSInteger amount = 0;
        for (MineOrderDetailModel *detailModel in model.detailArr) {
            NSInteger num = [detailModel.amount integerValue];
            amount = amount + num;
        }
        
        self.shopNumberLabel.text = [NSString stringWithFormat:@"共%ld件商品,合计",(long)amount];
        self.shopTotalPriceLabel.text = [NSString stringWithFormat:@"￥%@",model.total_amount];
    }
    
    if ([model.order_status isEqualToString:@"2"]) {
        self.querenBtn.hidden = YES;
    }
}

//当前视图
-(UIViewController *)currentViewController{
    UIViewController *vc;
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[objc_getClass("UIViewController") class]] ) {
            vc=(UIViewController*)nextResponder;
            
            return vc;
        }
    }
    return vc;
}

@end
